﻿/*********************************************************************************/
/**    Sims3Pack Readme Generator                                               **/
/**    Copyright (C) 2012  Anja Knackstedt                                      **/
/**                                                                             **/
/**    This program is free software: you can redistribute it and/or modify     **/
/**    it under the terms of the GNU General Public License as published by     **/
/**    the Free Software Foundation, either version 3 of the License, or        **/
/**    (at your option) any later version.                                      **/
/**                                                                             **/
/**    This program is distributed in the hope that it will be useful,          **/
/**    but WITHOUT ANY WARRANTY; without even the implied warranty of           **/
/**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            **/
/**    GNU General Public License for more details.                             **/
/**                                                                             **/
/**    You should have received a copy of the GNU General Public License        **/
/**    along with this program.  If not, see <http://www.gnu.org/licenses/>.    **/
/**                                                                             **/
/*********************************************************************************/




using System;
using System.Windows.Forms;
using System.IO;
using Sims3PackReadmeGenerator.ContentDesciption;
using Sims3PackReadmeGenerator.Sims3PackReader;
using Sims3PackReadmeGenerator.Layout;
using Sims3PackReadmeGenerator.language;
using System.Collections.Generic;

namespace Sims3PackReadmeGenerator.Gui
{
    /// <summary>
    /// main form
    /// displays information about opended sims 3 packs
    /// two views:
    /// overview: displays most of the available information
    /// output: output preview for the current layout
    /// </summary>
    partial class Sims3PackReadmeGenGui : Form
    {
        #region fields

        private Sims3PackReaderClass    _sims3packReader            = new Sims3PackReaderClass();
        private LayoutParser            _layoutParser               = new LayoutParser();
        private GroupBox                _detailsGroupBox;
        private Options                 _options                    = new Options();
        private LayoutCollectionManager _layoutCollectionManager    = new LayoutCollectionManager();
        
       
        private Panel                   _currentMainPanel;    // the shown panel
        private Panel                   _currentMainView;     // saves the current view (overview / output)   
        private EditReadmeLayoutGui     _editReadmeLayoutGui;


        private int[]                   _imageThumbPos;

        #endregion

        #region constructor

        public Sims3PackReadmeGenGui()
        {
            InitializeComponent();          

            Localization.init("Sims3PackReadmeGenerator.language.language", typeof(Sims3PackReadmeGenGui).Assembly);            
        }

        #endregion

        #region methods

        #region open files

        /// <summary>
        /// handles the open tools strip menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFiles();
        }        

        /// <summary>
        /// handles the open toolstrip button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            openFiles();
        }
       
        /// <summary>
        /// displays an open file dialog and opens the choosen sims3pack files
        /// </summary>
        private void openFiles()
        {
            DialogResult result;

            result = openSims3PackDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string[] fileNames = openSims3PackDialog.FileNames;

                if (fileNames.Length > 0)
                {
                    int endPosition = -1;
                    if (tsComboBoxFileName.Items.Count > 0)
                    {
                        endPosition = tsComboBoxFileName.Items.Count -1;
                    }

                    this.Cursor = Cursors.WaitCursor;

                    foreach (string fileName in fileNames)
                    {
                        try
                        {
                            ContentDescription description = _sims3packReader.readSims3PackFile(fileName);
                            if (description != null)
                            {
                                addContentDescription(description);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format(errors.errorOpenSims3Pack, fileName,ex.Message), 
                                            errors.errorOpenSims3PackTitle, 
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);    
                        }
                        
                    }

                    if (tsComboBoxFileName.Items.Count > 0)
                    {
                        tsComboBoxFileName.SelectedIndex = endPosition + 1;
                    }                   

                    this.Cursor = Cursors.Default;
                }                            
                              
            }
        }

        /// <summary>
        /// adds new contentdescription to the combobox
        /// and updates the form
        /// </summary>
        /// <param name="description"></param>
        private void addContentDescription(ContentDescription description)
        {
            //update combobox
            tsComboBoxFileName.Items.Add(description);
            tsComboBoxFileName.SelectedIndex = tsComboBoxFileName.Items.Count - 1;

            //enable file close buttons
            if (closeAllToolStripMenuItem.Enabled == false || closeOneToolStripMenuItem.Enabled == false)
            {
                closeOneToolStripMenuItem.Enabled = true;
                closeAllToolStripMenuItem.Enabled = true;
            }
            //enable create readme buttons
            if (tsBtReadmeOne.Enabled == false)
            {
                tsBtReadmeOne.Enabled = true;
                createReadmeToolStripMenuItem.Enabled = true;
            }
            //enable export image context menue
            if (contMenuExportImage.Enabled == false)
            {
                contMenuExportImage.Enabled = true;
                exportImageToolStripMenuItem.Enabled = true;
            }
        }

        #endregion

        #region close files

        /// <summary>
        /// closes the current file
        /// closing means only removing the contentdescription from the combobox list
        /// because the sims3pack file is not kept open after reading the information in
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tsComboBoxFileName.Items.Count > 1)
            {
                int currentPos = tsComboBoxFileName.SelectedIndex;
                tsComboBoxFileName.Items.Remove(tsComboBoxFileName.SelectedItem);

                if (currentPos > 0)
                {
                    tsComboBoxFileName.SelectedIndex = currentPos - 1;
                }
                else
                {
                    tsComboBoxFileName.SelectedIndex = 0;
                }
            }
            else if (tsComboBoxFileName.Items.Count == 1)
            {
                tsComboBoxFileName.Items.Remove(tsComboBoxFileName.SelectedItem);
                resetGui();
            }
        }

        /// <summary>
        /// handles the close all menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            closeAll();
        }

        /// <summary>
        /// closes all sims3pack files
        /// closing means only removing the contentdescription from the combobox list
        /// because the sims3pack file is not kept open after reading the information in
        /// </summary>
        private void closeAll()
        {
            tsComboBoxFileName.Items.Clear();
            resetGui();
        }

        #endregion

        #region display content

        /// <summary>
        /// handles the selected item changed event of the filename combobox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripComboBoxFileName_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            resetInformationOnGui();
            
            // activate arrows if more than one file
            if (tsComboBoxFileName.Items.Count > 1)
            {
                //chack if file list is at right or left end, then deactivate arrows
                int position = tsComboBoxFileName.SelectedIndex;
                if (position == 0)
                {
                    tSButtonLeft.Enabled = false;
                    tSButtonRight.Enabled = true;
                }
                else if (position == tsComboBoxFileName.Items.Count - 1)
                {
                    tSButtonRight.Enabled = false;
                    tSButtonLeft.Enabled = true;
                }
                else
                {
                    tSButtonRight.Enabled = true;
                    tSButtonLeft.Enabled = true;
                }

            }

            ContentDescription contentDescription = tsComboBoxFileName.SelectedItem as ContentDescription;

            if (contentDescription != null)
            {
                displayContent(contentDescription);
                updateOutputContent();
            }
            
        }

        /// <summary>
        /// handles the oveview menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void overviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            displayViewOverview();
        }

        /// <summary>
        /// activates the overview view
        /// </summary>
        private void displayViewOverview()
        {
            activateMainPanel(panelOverview);
            _currentMainView = panelOverview;
            overviewToolStripMenuItem.Checked = true;
            overviewToolStripMenuItem1.Checked = true;
            outputToolStripMenuItem.Checked = false;
            outputViewToolStripMenuItem2.Checked = false;
        }

        /// <summary>
        /// handles the output menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void outputToolStripMenuItem_Click(object sender, EventArgs e)
        {

            displayViewOutput();
        }

        /// <summary>
        /// activates the output view
        /// </summary>
        private void displayViewOutput()
        {
            overviewToolStripMenuItem.Checked = false;
            overviewToolStripMenuItem1.Checked = false;
            outputToolStripMenuItem.Checked = true;
            outputViewToolStripMenuItem2.Checked = true;

            activateMainPanel(panelOutput);
            _currentMainView = panelOutput;
            txtOutputPath.Text = Properties.Settings.Default.OutputFolder;
            updateOutputContent();
        }

        /// <summary>
        /// activates overview view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void overviewToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            displayViewOverview();
        }

        /// <summary>
        /// activates output view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void outputToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            displayViewOutput();
        }

        #region display content overview

        /// <summary>
        /// show common information for content description
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayContent(ContentDescription contentDescription)
        {
            txtName.Text = contentDescription.DisplayName;
            txtDescription.Text = contentDescription.Description;

            // check if bad cc is found
            if (contentDescription.getBadCCList().Count > 0)
            {
                panelWarningBadCC.Enabled = true;
                showWarnings(true);
            }

            // check if unknown packages were found
            if (contentDescription.getUnknownPackagesList().Count > 0)
            {
                panelWarningUnknownCC.Enabled = true;
                showWarnings(true);
            }

            // check if at leats one thumbnail is found (tsrw files have no thumbnails)
            if (contentDescription.getThumbnailList().Count > 0)
            {
                picBoxThumbnail.Image = contentDescription.getThumbnailList()[0];
                picBoxThumb1.Enabled = true;
                picBoxThumb1.Image = contentDescription.getThumbnailList()[0];
                
                _imageThumbPos[0] = 0;

                contMenuExportImage.Enabled = true;
                exportImageToolStripMenuItem.Enabled = true;
                btThumPrev.Enabled = false;
                btThumbNext.Enabled = false;
                if (contentDescription.getThumbnailList().Count > 1)
                {
                    picBoxThumb2.Enabled = true;
                    picBoxThumb2.Image = contentDescription.getThumbnailList()[1];
                    _imageThumbPos[1] = 1;

                    if (contentDescription.getThumbnailList().Count > 2)
                    {
                        picBoxThumb3.Enabled = true;
                        picBoxThumb3.Image = contentDescription.getThumbnailList()[2];
                        _imageThumbPos[2] =2;

                        if (contentDescription.getThumbnailList().Count > 3)
                        {
                            //activate browse buttons when more than 3 thumbs
                            btThumbNext.Enabled = true;
                        }
                    }
                }

            }
            else
            {
                contMenuExportImage.Enabled = false;
                exportImageToolStripMenuItem.Enabled = false;
            }
                        
            txtType.Text = contentDescription.getContentType(Languages.de);	        
            
            txtGameversion.Text = contentDescription.GameVersion;
            txtExpansion.Text = contentDescription.getExpansionList(Languages.de);
            txtStuffpack.Text = contentDescription.getStuffpackList(Languages.de);
            txtPackagedFiles.Text = contentDescription.getKnownPackagesListSimple(Languages.de);

            // check if store properties are resolved
            if (Properties.Settings.Default.UseS3SBrowserData)
            {
                txtStore.Text = contentDescription.getStoreList(Languages.de);
            }
            else
            {
                groupBoxStoreItems.Enabled = false;
                txtStore.Text = messages.messageStoreDependenciesNotResolved;
            }            

            displayDetails(contentDescription);
        }

        /// <summary>
        /// shows the Warning Gropubox
        /// shows the text 'warnings' and the warning panels or hides them
        /// </summary>
        /// <param name="show">true to show warnings</param>
        private void showWarnings(bool show)
        {
            panelWarningBadCC.Visible       = show;
            panelWarningUnknownCC.Visible   = show;

            if (show)
            {
                groupBoxWarning.Text = names.mainFormWarnings;
            }
            else
            {
                groupBoxWarning.Text = "";
            }
            
        }

        /// <summary>
        /// displays specifics information for a given content desription type
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayDetails(ContentDescription contentDescription)
        {
            switch (contentDescription.Type)
            {
                case ContentTypes.sim:
                    activateDetailsGroupBox(groupBoxSimDetails);
                    displaySimDetail(contentDescription);
                    break;
                case ContentTypes.household:
                    activateDetailsGroupBox(groupBoxHouseholdDetails);
                    displayHouseholdDetail(contentDescription);
                    break;
                case ContentTypes.lot:
                    activateDetailsGroupBox(groupBoxLotDetails);
                    displayLotDetail(contentDescription);
                    break;
                case ContentTypes.world:
                    activateDetailsGroupBox(groupBoxWorldDetails);
                    displayWorldDetail(contentDescription);
                    break;
                case ContentTypes.preset:
                    activateDetailsGroupBox(groupBoxPresetDetails);
                    displayPresetDetails(contentDescription);
                    break;
                case ContentTypes.haircolorinfo:
                    groupBoxNoDetails.Text = names.mainFormGroupBoxHaircolor;
                    activateDetailsGroupBox(groupBoxNoDetails);
                    break;
                case ContentTypes.coatset:
                    activateDetailsGroupBox(groupBoxCoatsetDetails);
                    displayCoatsetDetails(contentDescription);
                    break;
                case ContentTypes.pattern:                    
                case ContentTypes.cascolorinfo:
                    activateDetailsGroupBox(groupBoxPatternDetails);
                    displayPatternDetails(contentDescription);
                    break;
                case ContentTypes.CASPart:
                    groupBoxNoDetails.Text = names.mainFormGroupBoxCasElement;
                    activateDetailsGroupBox(groupBoxNoDetails);
                    break;
                case ContentTypes.gameobject:
                    groupBoxNoDetails.Text = names.mainFormGroupBoxCasObject;
                    activateDetailsGroupBox(groupBoxNoDetails);
                    break;
                default:
                    activateDetailsGroupBox(groupBoxUnknownDetails);
                    break;
            }
                       
        }

        /// <summary>
        /// display pattern specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayPatternDetails(ContentDescription contentDescription)
        {
            PackagedPatternDescription desrc = contentDescription.PackagedMainFile as PackagedPatternDescription;
            if (desrc != null)
            {
                txtPatternCategory.Text = desrc.getCategory(Languages.de);
            }
            
        }

        /// <summary>
        /// display coatset specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayCoatsetDetails(ContentDescription contentDescription)
        {
            PackagedCoatsetDescription desrc = contentDescription.PackagedMainFile as PackagedCoatsetDescription;
            if (desrc != null)
            {
                txtCoatsetAge.Text = desrc.getAge(Languages.de);
                txtCoatsetSpecies.Text = desrc.getSpecies(Languages.de);
            }
        }

        /// <summary>
        /// display preset specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayPresetDetails(ContentDescription contentDescription)
        {
            PackagedPresetDescription desrc = contentDescription.PackagedMainFile as PackagedPresetDescription;
            if (desrc != null)
            {
                txtPresetAge.Text = desrc.getPresetAge(Languages.de);
                txtPresetGender.Text = desrc.getPresetGender(Languages.de);
            }
        }

        /// <summary>
        /// display world specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayWorldDetail(ContentDescription contentDescription)
        {
            PackagedWorldDescription worldDescription = contentDescription.PackagedMainFile as PackagedWorldDescription;

            if (worldDescription != null)
            {
                txtWorldComLotCount.Text    = worldDescription.WorldNumCommercialLots;
                txtWorldLotCount.Text       = worldDescription.WorldNoLots;
                txtWorldResLotCount.Text    = worldDescription.WorldNumResidentialLots;
                txtWorldSimCount.Text       = worldDescription.WorldNumSims;
                txtWorlOccupiedCount.Text   = worldDescription.WorldNumOccupiedLots;
                txtWorldSize.Text           = worldDescription.getWorldSize();
            }
        }

        /// <summary>
        /// displays lot specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayLotDetail(ContentDescription contentDescription)
        {
            PackagedLotDescription lotDescription = contentDescription.PackagedMainFile as PackagedLotDescription;

            if (lotDescription != null)
            {
                //occupied lot
                if (lotDescription.IsOccupied)
                {
                    groupBoxLotMember.Enabled = true;
                    foreach (SimpleSimDescription simDescription in lotDescription.getSimsList())
                    {
                        comboBoxLotMember.Items.Add(simDescription);
                    }
                    if (comboBoxLotMember.Items.Count > 0)
                    {
                        comboBoxLotMember.SelectedIndex = 0;
                    }
                }
                //unoccupied lot
                else
                {
                    groupBoxLotMember.Enabled = false;
                    clearLotDetails();
                }

                txtLotType.Text = lotDescription.getLotType(Languages.de);
                txtLotSize.Text = lotDescription.getLotSize();
            }

        }

        /// <summary>
        /// displays houshold specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displayHouseholdDetail(ContentDescription contentDescription)
        {
            PackagedHouseholdDescription householdDescription = contentDescription.PackagedMainFile as PackagedHouseholdDescription;

            if (householdDescription != null)
            {

                txtHouseholdName.Text = householdDescription.getHouseholdName();
                txtHouseholdFunds.Text = householdDescription.getHousholdFunds();                

                groupBoxLotMember.Enabled = true;
                foreach (SimpleSimDescription simDescription in householdDescription.getSimsList())
                {
                    comboBoxHouseholdMember.Items.Add(simDescription);
                }
                if (comboBoxHouseholdMember.Items.Count > 0)
                {
                    comboBoxHouseholdMember.SelectedIndex = 0;
                }                
            }
        }

        /// <summary>
        /// displays sim specific info
        /// </summary>
        /// <param name="contentDescription"></param>
        private void displaySimDetail(ContentDescription contentDescription)
        {
            PackagedSimDescription simDescription = contentDescription.PackagedMainFile as PackagedSimDescription;
            if (simDescription != null)
            {
                txtAge.Text = simDescription.Age.DE;
                txtGender.Text = simDescription.Gender.DE;                
                txtTraits.Text = simDescription.getTraitList(Languages.de);
                
                //only sims have favourites, animals not
                if (simDescription.SimType == SimTypes.sim)
                {
                    txtFavs.Text = simDescription.getFavList(Languages.de);
                }                
                txtBio.Text = simDescription.Bio;
            }
        }

        /// <summary>
        /// handles the combobox lot member selected index change event
        /// displays the chosen lot member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxLotMember_SelectedIndexChanged(object sender, EventArgs e)
        {
            SimpleSimDescription simDescription = comboBoxLotMember.SelectedItem as SimpleSimDescription;
            if (simDescription != null)
            {
                txtLotAge.Text = simDescription.Age.DE;
                txtLotGender.Text = simDescription.Gender.DE;
                txtLotBio.Text = simDescription.Bio;
            }
        }

        /// <summary>
        /// handles the combobox household member selected index change event
        /// displays the chosen household member
        private void comboBoxHouseholdMember_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            SimpleSimDescription simDescription = comboBoxHouseholdMember.SelectedItem as SimpleSimDescription;
            if (simDescription != null)
            {

                txtHouseholdAge.Text = simDescription.Age.DE;
                txtHouseholdGender.Text = simDescription.Gender.DE;
                txtHousholtBio.Text = simDescription.Bio;

            }
        }

        #endregion

        #endregion

        #region reset gui

        /// <summary>
        /// clears preset specific gui
        /// </summary>
        private void clearPresetDetails()
        {
            txtPresetAge.Text = "";
            txtPresetGender.Text = "";
        }

        /// <summary>
        /// clears pattern specific gui
        /// </summary>
        private void clearPatternDetails()
        {
            txtPatternCategory.Text = "";
        }

        /// <summary>
        /// clears coatset specific gui
        /// </summary>
        private void clearCoatsetDetails()
        {
            txtCoatsetAge.Text = "";
            txtCoatsetSpecies.Text = "";
        }

        /// <summary>
        /// clears world specific gui
        /// </summary>
        private void clearWorldDetails()
        {
            txtWorldComLotCount.Text = "";
            txtWorldLotCount.Text = "";
            txtWorldResLotCount.Text = "";
            txtWorldSimCount.Text = "";
            txtWorlOccupiedCount.Text = "";
            txtWorldSize.Text = "";
        }

        /// <summary>
        /// clears lot specific details
        /// </summary>
        private void clearLotDetails()
        {
            comboBoxLotMember.Items.Clear();
            comboBoxLotMember.Text = "";
            txtLotType.Text = "";
            txtLotSize.Text = "";
            txtLotGender.Text = "";
            txtLotAge.Text = "";
            txtLotBio.Text = "";
        }

        /// <summary>
        /// clears houshold specific gui
        /// </summary>
        private void clearHouseholdDetails()
        {
            comboBoxHouseholdMember.Items.Clear();
            comboBoxHouseholdMember.Text = "";
            txtHouseholdFunds.Text = "";
            txtHouseholdGender.Text = "";
            txtHouseholdName.Text = "";
            txtHouseholdAge.Text = "";
            txtHousholtBio.Text = "";
        }

        /// <summary>
        /// clears sim specific gui
        /// </summary>
        private void clearSimDetails()
        {
            txtAge.Text = "";
            txtGender.Text = "";
            txtBio.Text = "";
            txtFavs.Text = "";
            txtTraits.Text = "";
        }

        /// <summary>
        /// resets the complete gui
        /// </summary>
        private void resetGui()
        {
            // deactivate buttons
            closeAllToolStripMenuItem.Enabled = false;
            closeOneToolStripMenuItem.Enabled = false;
            tSButtonLeft.Enabled = false;
            tSButtonRight.Enabled = false;

            tsBtReadmeOne.Enabled = false;
            createReadmeToolStripMenuItem.Enabled = false;

            // deactivate context menue
            contMenuExportImage.Enabled = false;
            exportImageToolStripMenuItem.Enabled = false;

            resetInformationOnGui();

        }

        /// <summary>
        /// resets all displayed information
        /// </summary>
        private void resetInformationOnGui()
        {

            txtOutputLeft.Text = "";

            tsComboBoxFileName.Text = "";
            txtName.Text = "";
            txtDescription.Text = "";
            picBoxThumbnail.Image = null;
            picBoxThumb1.Image = null;
            picBoxThumb2.Image = null;
            picBoxThumb3.Image = null;
            picBoxThumb1.Enabled = false;
            picBoxThumb2.Enabled = false;
            picBoxThumb3.Enabled = false;
            txtGameversion.Text = "";
            txtType.Text = "";
            txtExpansion.Text = "";
            txtStore.Text = "";
            groupBoxStoreItems.Enabled = true;
            txtStuffpack.Text = "";
            txtPackagedFiles.Text = "";
            panelWarningBadCC.Enabled = false;
            panelWarningUnknownCC.Enabled = false;
            showWarnings(false);

            clearHouseholdDetails();
            clearLotDetails();
            clearSimDetails();
            clearWorldDetails();
            clearCoatsetDetails();
            clearPatternDetails();
            clearPresetDetails();

            activateDetailsGroupBox(groupBoxUnknownDetails);
        }

        #endregion       

        #region display output

        /// <summary>
        /// updates the layout collection combobox
        /// the selected index is saved while updating
        /// </summary>
        private void updateLayoutCollectionsOutput()
        {
            int selectedIndex = cbLayoutCollectionsLeft.SelectedIndex;
            //when combobox was empty, select the first entry
            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            cbLayoutCollectionsLeft.DataSource = null;
            cbLayoutCollectionsLeft.DataSource = _layoutCollectionManager.LayoutCollections;
            //when previous selected item was deleted choose first entry
            if (selectedIndex >= cbLayoutCollectionsLeft.Items.Count)
            {
                selectedIndex = 0;
            }
            cbLayoutCollectionsLeft.SelectedIndex = selectedIndex;

            listBoxLayoutCollection.Items.Clear();
            int index = 0;
            foreach (ILayoutCollection layoutCollection in _layoutCollectionManager.LayoutCollections)
            {
                listBoxLayoutCollection.Items.Add(layoutCollection);
                listBoxLayoutCollection.SetItemChecked(index, layoutCollection.IsChoosenForOutput);
                index++;
            }
        }
       
        /// <summary>
        /// update the shwon output
        /// </summary>
        private void updateOutputContent()
        {
            string output = "";

            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;

            if (description != null)
            {
                ILayoutCollection layoutCollectionLeft = cbLayoutCollectionsLeft.SelectedItem as ILayoutCollection;

                if (layoutCollectionLeft != null)
                {
                    //parse chosen layout
                    output = _layoutParser.parseLayout(description, layoutCollectionLeft);
                }   
            }
            txtOutputLeft.Text = output;            
        }

        #endregion

        #region edit layouts

        /// <summary>
        /// handles the design menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void designToolStripMenuItem_Click(object sender, EventArgs e)
        {
            displayLayoutEditForm();            
        }

       /// <summary>
       /// displays the edit layout form
       /// </summary>
        private void displayLayoutEditForm()
        {
            designToolStripMenuItem.Enabled = false;
            btLayoutEdit.Enabled = false;

            // get current content type, use layout type and not sims3pack content type
            // e.g. there are different layouts for community and residential lost
            LayoutTypes type = LayoutTypes.common;

            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
            if (description != null)
            {                
                switch (description.Type)
                {
                    case ContentTypes.sim:
                        PackagedSimDescription simDescription = description.PackagedMainFile as PackagedSimDescription;
                        if (simDescription != null)
                        {
                            if (simDescription.IsAnimal)
                            {
                                type = LayoutTypes.animal;
                            }
                            else
                            {
                                type = LayoutTypes.sim;
                            }
                        }
                        break;
                    case ContentTypes.household:
                        type = LayoutTypes.household;
                        break;
                    case ContentTypes.lot:
                        PackagedLotDescription lotDesription = description.PackagedMainFile as PackagedLotDescription;
                        if (lotDesription != null)
                        {
                            if (lotDesription.IsCommunityLot)
                            {
                                type = LayoutTypes.comlot;
                            }
                            else if (lotDesription.IsOccupied)
                            {
                                type = LayoutTypes.reslotocc;
                            }
                            else
                            {
                                type = LayoutTypes.reslot;
                            }
                        }
                        break;
                    case ContentTypes.world:
                        type = LayoutTypes.world;
                        break;
                    case ContentTypes.preset:
                        type = LayoutTypes.preset;
                        break;
                    case ContentTypes.haircolorinfo:
                        type = LayoutTypes.common;
                        break;
                    case ContentTypes.coatset:
                        type = LayoutTypes.coatset;
                        break;
                    case ContentTypes.pattern:
                        type = LayoutTypes.pattern;
                        break;
                    case ContentTypes.cascolorinfo:
                        type = LayoutTypes.pattern;
                        break;
                    case ContentTypes.CASPart:
                        type = LayoutTypes.common;
                        break;
                    case ContentTypes.gameobject:
                        type = LayoutTypes.common;
                        break;
                    case ContentTypes.unknown:
                        type = LayoutTypes.common;
                        break;
                    default:
                        type = LayoutTypes.common;
                        break;
                }
            }

           
            _editReadmeLayoutGui = new EditReadmeLayoutGui(_layoutCollectionManager.LayoutCollections ,type);

            //register for events
            _editReadmeLayoutGui.OnUpdateLayoutHandler              += new EditReadmeLayoutGui.EditReadmeFormEventHandler(_editReadmeLayoutGui_OnUpdateLayoutHandler);
            _editReadmeLayoutGui.OnFormClosingHandler               += new EditReadmeLayoutGui.EditReadmeFormEventHandler(_editReadmeLayoutGui_OnFormClosingHandler);
            _editReadmeLayoutGui.OnUpdateLayoutCollectionsHandler   += new EditReadmeLayoutGui.EditReadmeFormEventHandler(_editReadmeLayoutGui_OnUpdateLayoutCollectionsHandler);
            
            _editReadmeLayoutGui.Show();
        }

        /// <summary>
        /// handle the OnUpdateLayoutCollections event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _editReadmeLayoutGui_OnUpdateLayoutCollectionsHandler(object sender, EventArgs e)
        {
            _layoutCollectionManager.LayoutCollections = _editReadmeLayoutGui.LayoutCollections;
            updateLayoutCollectionsOutput();
        }

        /// <summary>
        /// handles the OnFormClosing event of the edit layout form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _editReadmeLayoutGui_OnFormClosingHandler(object sender, EventArgs e)
        {
            //when layout design is closed, activate buttons again
            designToolStripMenuItem.Enabled = true;
            btLayoutEdit.Enabled = true;
            
             _layoutCollectionManager.LayoutCollections = _editReadmeLayoutGui.LayoutCollections;
             updateLayoutCollectionsOutput();
        }

        /// <summary>
        /// handles the OnUpdateLayout layout event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _editReadmeLayoutGui_OnUpdateLayoutHandler(object sender, EventArgs e)
        {            
            updateOutputContent();
        }

        #endregion

        #region overview specific gui methods

        #region display thumbnail gui methods

        /// <summary>
        /// handles the thumb next button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btThumbNext_Click(object sender, EventArgs e)
        {
            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
            if (description != null)
            {
                //when next is clicked, prev can be enabled
                btThumPrev.Enabled = true;

                //check if listend
                if (_imageThumbPos[2] + 2 == description.getThumbnailList().Count)
                {
                    btThumbNext.Enabled = false;
                    btThumPrev.Focus();
                }
                _imageThumbPos[0]++;
                picBoxThumb1.Image = description.getThumbnailList()[_imageThumbPos[0]];
                _imageThumbPos[1]++;
                picBoxThumb2.Image = description.getThumbnailList()[_imageThumbPos[1]];
                _imageThumbPos[2]++;
                picBoxThumb3.Image = description.getThumbnailList()[_imageThumbPos[2]];

                picBoxThumbnail.Image = picBoxThumb1.Image;
            }
        }

        /// <summary>
        /// handles the thumb prev button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btThumPrev_Click(object sender, EventArgs e)
        {
            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
            if (description != null)
            {
                //when prev is clicked, next can be enabled
                btThumbNext.Enabled = true;

                //check for list end
                if (_imageThumbPos[0] - 1 == 0)
                {
                    btThumPrev.Enabled = false;
                    btThumbNext.Focus();

                }
                _imageThumbPos[0]--;
                picBoxThumb1.Image = description.getThumbnailList()[_imageThumbPos[0]];
                _imageThumbPos[1]--;
                picBoxThumb2.Image = description.getThumbnailList()[_imageThumbPos[1]];
                _imageThumbPos[2]--;
                picBoxThumb3.Image = description.getThumbnailList()[_imageThumbPos[2]];

                picBoxThumbnail.Image = picBoxThumb1.Image;
            }
        }

        /// <summary>
        /// display clicked image in picture box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picBoxThumb1_Click(object sender, EventArgs e)
        {
            picBoxThumbnail.Image = picBoxThumb1.Image;
        }

        /// <summary>
        /// display clicked image in picture box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picBoxThumb2_Click(object sender, EventArgs e)
        {
            picBoxThumbnail.Image = picBoxThumb2.Image;
        }

        /// <summary>
        /// display clicked image in picture box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picBoxThumb3_Click(object sender, EventArgs e)
        {
            picBoxThumbnail.Image = picBoxThumb3.Image;
        }

        #endregion

        #region export image

        /// <summary>
        /// handles the export image context menue item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            exportImage();
        }

        /// <summary>
        /// handles the export image menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportCurrentImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            exportImage();
        }

        /// <summary>
        /// exports the current displayed thumbnail image as png
        /// </summary>
        private void exportImage()
        {
            DialogResult result;

            ContentDescription currentItem = tsComboBoxFileName.SelectedItem as ContentDescription;

            if (currentItem != null)
            {
                FileInfo info = new FileInfo(currentItem.getFileName());
                string extension = info.Extension;
                saveImageDialog.FileName = info.Name.Replace(extension, ".png");
            }
            result = saveImageDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                picBoxThumbnail.Image.Save(saveImageDialog.FileName);
            }
        }

        #endregion

        #region bad cc details

        /// <summary>
        /// display bad cc details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btBadCCDetails_Click(object sender, EventArgs e)
        {
            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
            if (description != null)
            {
                BadCCDetailsGui badCCGui = new BadCCDetailsGui(description.getBadCCList());
                badCCGui.ShowDialog();
            }

        }
        
        #endregion

        #region unknown cc details

        /// <summary>
        /// displays details for unknown packages
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btUnknownPackDetails_Click(object sender, EventArgs e)
        {
            ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
            if (description != null)
            {
                UnknownPackagesDetailsGui unknownPackageForm = new UnknownPackagesDetailsGui(description.getUnknownPackagesList());               
                unknownPackageForm.ShowDialog();
            }
        }       

        #endregion

        #endregion

        #region output specific gui methods

        /// <summary>
        /// sets the ouput folder for readmes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSaveDirectory_Click(object sender, EventArgs e)
        {
             DialogResult result;
            
            result = folderBrowserDialogOutput.ShowDialog();

            if (result == DialogResult.OK)
            {
                string folderPath = folderBrowserDialogOutput.SelectedPath;
                txtOutputPath.Text = folderPath;
                Properties.Settings.Default.OutputFolder = folderPath;
            }
        }

        /// <summary>
        /// updates the creator info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtOutputCreator_TextChanged(object sender, EventArgs e)
        {
            _layoutParser.Creator = txtOutputCreator.Text;
            updateOutputContent();
        }

        /// <summary>
        /// updates the homepage info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtOutputHomepage_TextChanged(object sender, EventArgs e)
        {
            _layoutParser.Homepage = txtOutputHomepage.Text;
            updateOutputContent();
        }

        /// <summary>
        /// displays the edit layout form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btLayoutEdit_Click(object sender, EventArgs e)
        {
            displayLayoutEditForm();
        }

        /// <summary>
        /// use sims3pack name as output filename
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioFileNameSims3Pack_CheckedChanged(object sender, EventArgs e)
        {
            txtOutputFileName.Enabled = false;
        }

        /// <summary>
        /// use custom filename
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioCustomFileName_CheckedChanged(object sender, EventArgs e)
        {
            txtOutputFileName.Enabled = true;
        }

        /// <summary>
        /// set if layout collection is chosen for output
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBoxLayoutCollection_ItemCheck(object sender, ItemCheckEventArgs e)
        {

            ILayoutCollection layoutCollection = listBoxLayoutCollection.Items[e.Index] as ILayoutCollection;
            if (layoutCollection != null)
            {
                if (e.NewValue == CheckState.Checked)
                    layoutCollection.IsChoosenForOutput = true;
                else if (e.NewValue == CheckState.Unchecked)
                    layoutCollection.IsChoosenForOutput = false;
            }


        }

        /// <summary>
        /// update outbut when new layout collection chosen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbLayoutCollectionsLeft_SelectedIndexChanged(object sender, EventArgs e)
        {
            updateOutputContent();
        }

        #endregion

        #region write readmes

        private void tsBtReadmeOne_Click(object sender, EventArgs e)
        {
            writeReadmes();
        }

        private void createReadmeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            writeReadmes();
        }

        /// <summary>
        /// creates readmes for current content description
        /// </summary>
        private void writeReadmes()
        {
            try
            {
                ContentDescription description = tsComboBoxFileName.SelectedItem as ContentDescription;
                if (description != null)
                {

                    List<ILayoutCollection> layoutCollections = _layoutCollectionManager.LayoutCollections;
                    if (layoutCollections!=null)
                    {
                        foreach (ILayoutCollection layoutCollection in layoutCollections)
                        {
                            if (layoutCollection.IsChoosenForOutput)
                            {
                                //set the output filename
                                string outputFileName;

                                if (radioFileNameSims3Pack.Checked)
                                {

                                    outputFileName = description.getFileName();

                                    FileInfo info = new FileInfo(description.FilePath);
                                    string extensionOld = info.Extension;
                                    string extensionNew = string.Format("{0}.txt", layoutCollection.SaveFileIdCode);

                                    outputFileName = outputFileName.Replace(extensionOld, extensionNew);
                                }
                                else
                                {
                                    outputFileName = string.Format("{0}{1}.txt",txtOutputFileName.Text, layoutCollection.SaveFileIdCode);
                                }
                               
                                //set the output path
                                string folderpath = Properties.Settings.Default.OutputFolder;
                                if (folderpath == "")
                                {
                                    folderpath = FilePaths.appMyDocPath;
                                }

                                bool isFileWrite = true;

                                //check if file already exists, override file?
                                if (File.Exists(string.Format(@"{0}\{1}",folderpath, outputFileName)))
                                {
                                    isFileWrite = false;
                                    if (MessageBox.Show(    string.Format(  messages.messageReadmeFileExists,
                                                                            description.getFileName(),
                                                                            layoutCollection.ToString(), 
                                                                            outputFileName), 
                                                            messages.messageReadmeFileExistsTitle, 
                                                            MessageBoxButtons.YesNo) == DialogResult.Yes)
                                    {
                                        isFileWrite = true;
                                    }
                                }

                                if (isFileWrite)
                                {
                                    System.IO.File.WriteAllText(string.Format(@"{0}\{1}", folderpath, outputFileName), txtOutputLeft.Text);
                                    MessageBox.Show(    string.Format(messages.messageReadmeFileCreated, outputFileName, folderpath), 
                                                        messages.messageReadmeFileCreatedTitle, 
                                                        MessageBoxButtons.OK);
                                }
                            }
                        }
                    }                   
                }
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message, errors.errorWriteReadme);
            }

         }

        #endregion

        #region options

        /// <summary>
        /// shows options dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void optionenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showOptions();
        }

        /// <summary>
        /// shows options dialog
        /// </summary>
        private void showOptions()
        {
            OptionsGui optionsForm = new OptionsGui(_options);
            optionsForm.OnReloadStoreInfoHandler += new OptionsGui.OptionsFormEventHandler(optionsForm_OnReloadStoreInfoHandler);
            optionsForm.OnDisableStoreInfoHandler += new OptionsGui.OptionsFormEventHandler(optionsForm_OnDisableStoreInfoHandler);
            optionsForm.ShowDialog();
        }

        /// <summary>
        /// handle options OnDisableStoreInfo event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void optionsForm_OnDisableStoreInfoHandler(object sender, EventArgs e)
        {
            askForCloseAll();
        }

        /// <summary>
        /// handles options OnReloadStoreInfo event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void optionsForm_OnReloadStoreInfoHandler(object sender, EventArgs e)
        {
            _sims3packReader.ReferenceResolver.readStoreDependencies();
            askForCloseAll();     
        }

        #endregion

        #region manage bad cc

        /// <summary>
        /// display manage bad cc form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void manageBadCCPackagesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ManageBadCCInfoGui manageBadCCform = new ManageBadCCInfoGui();
            manageBadCCform.OnBadCCInfoUpdateHandler += new ManageBadCCInfoGui.ManageBadCCInfoFormEventHandler(manageBadCCform_OnBadCCInfoUpdateHandler);
            manageBadCCform.ShowDialog();
        }

        /// <summary>
        /// handles bad cc update event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void manageBadCCform_OnBadCCInfoUpdateHandler(object sender, EventArgs e)
        {
            _sims3packReader.ReferenceResolver.clearBadCCInformation();
            _sims3packReader.ReferenceResolver.readBadCCInformation();
            askForCloseAll();
        }

        #endregion

        #region manage known cc

        /// <summary>
        /// display manage known packages form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void knownPackagesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ManageKnownPackagesInfoGui manageBadCCform = new ManageKnownPackagesInfoGui();
            manageBadCCform.OnPackagesInfoUpdateHandler += new ManageKnownPackagesInfoGui.ManageKnownPackagesEventHandler(manageBadCCform_OnPackagesInfoUpdateHandler);
            manageBadCCform.ShowDialog();
        }

        /// <summary>
        /// handles known package info update event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void manageBadCCform_OnPackagesInfoUpdateHandler(object sender, EventArgs e)
        {
            _sims3packReader.ReferenceResolver.clearKnownCCInformation();
            _sims3packReader.ReferenceResolver.readKnownPackageInformation();
            askForCloseAll();
        }

        #endregion

        /// <summary>
        /// handles the click event of the exit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// initializes the gui
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Sims3PackReadmeGenGui_Load(object sender, EventArgs e)
        {            
            _layoutCollectionManager.loadLayouts();
            updateLayoutCollectionsOutput();

            //array for current shown images
            _imageThumbPos = new int[3];

            //add changing group boxes to parent panel
            panelDetailsBorder.Controls.Add(groupBoxUnknownDetails);
            panelDetailsBorder.Controls.Add(groupBoxSimDetails);
            panelDetailsBorder.Controls.Add(groupBoxLotDetails);
            panelDetailsBorder.Controls.Add(groupBoxHouseholdDetails);
            panelDetailsBorder.Controls.Add(groupBoxNoDetails);
            panelDetailsBorder.Controls.Add(groupBoxWorldDetails);
            panelDetailsBorder.Controls.Add(groupBoxPresetDetails);
            panelDetailsBorder.Controls.Add(groupBoxPatternDetails);
            panelDetailsBorder.Controls.Add(groupBoxCoatsetDetails);

            //activate the overview panel
            panelMain.Controls.Add(panelOverview);
            panelOutput.Visible = false;
            panelOverview.Visible = true;
            panelOverview.Dock = DockStyle.Fill;


            _currentMainPanel = this.panelOverview;
            _currentMainView = this.panelOverview;

            //activate the unknown type gropu box
            _detailsGroupBox = this.groupBoxUnknownDetails;
            groupBoxUnknownDetails.Dock = DockStyle.Fill;
            groupBoxUnknownDetails.Visible = true;

            //arrows for file navigation
            tSButtonLeft.Enabled = false;
            tSButtonRight.Enabled = false;

            //disable close file button
            closeOneToolStripMenuItem.Enabled = false;
            closeAllToolStripMenuItem.Enabled = false;

            //disable export image button
            contMenuExportImage.Enabled = false;
            exportImageToolStripMenuItem.Enabled = false;

            //disable create readme           
            tsBtReadmeOne.Enabled = false;
            createReadmeToolStripMenuItem.Enabled = false;

            //actiavte overview in view menue
            overviewToolStripMenuItem.Checked = true;
            overviewToolStripMenuItem1.Checked = true;

            //in load output view info from user settings
            txtOutputCreator.Text = Properties.Settings.Default.Creator;
            txtOutputHomepage.Text = Properties.Settings.Default.Homepage;

        }

        /// <summary>
        /// handles the form closing event
        /// saves all user settings
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Sims3PackReadmeGenGui_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.Settings.Default.Homepage = txtOutputHomepage.Text;
            Properties.Settings.Default.Creator = txtOutputCreator.Text;
            Properties.Settings.Default.Save();

            _layoutCollectionManager.saveLayouts();
        }

        /// <summary>
        /// activates a given details groupbox
        /// </summary>
        /// <param name="detailsBox"></param>
        private void activateDetailsGroupBox(GroupBox detailsBox)
        {
            _detailsGroupBox.Dock = DockStyle.None;
            _detailsGroupBox.Visible = false;
            _detailsGroupBox = detailsBox;

            detailsBox.Dock = DockStyle.Fill;
            detailsBox.Visible = true;
        }

        /// <summary>
        /// uses a given panel as main panel
        /// </summary>
        /// <param name="panel"></param>
        private void activateMainPanel(Panel panel)
        {
            _currentMainPanel.Dock = DockStyle.None;
            _currentMainPanel.Visible = false;
            _currentMainPanel = panel;

            panel.Dock = DockStyle.Fill;
            panel.Visible = true;
        }

        /// <summary>
        /// handles the right button click event
        /// activates the next sims3pack file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tSButtonRight_Click(object sender, EventArgs e)
        {
            int currentPos = tsComboBoxFileName.SelectedIndex;
            if (currentPos + 1 <= tsComboBoxFileName.Items.Count - 1)
            {
                tsComboBoxFileName.SelectedIndex = currentPos + 1;
            }
        }

        /// <summary>
        /// handles the left button click event
        /// activates the previous sims3pack file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tSButtonLeft_Click(object sender, EventArgs e)
        {
            int currentPos = tsComboBoxFileName.SelectedIndex;
            if (currentPos - 1 >= 0)
            {
                tsComboBoxFileName.SelectedIndex = currentPos - 1;
            }
        }

        /// <summary>
        /// asks for closing all open files
        /// </summary>
        void askForCloseAll()
        {
            if (tsComboBoxFileName.Items.Count > 0)
            {
                DialogResult result = MessageBox.Show(messages.messageCloseAlleOpenFiles,
                                                        messages.messageCloseAlleOpenFilesTitle,
                                                        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                    closeAll();
                }
            }
        }

        /// <summary>
        /// displays the info form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsMenuItemInfo_Click(object sender, EventArgs e)
        {
            InfoGui infoForm = new InfoGui();
            infoForm.ShowDialog();
        }

        /// <summary>
        /// displays the help
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsMenuItemHelp_Click(object sender, EventArgs e)
        {
            Help.ShowHelp(this, FilePaths.helpFilePath);           
        }
        #endregion

    }
}
